package uTatrusTests;

import static org.junit.Assert.*;

import java.awt.Color;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
 * <p>Title: Shape.class Unit Tests </p>
 * <p>Description: CSIS 343 Course Project</p>
 * 
 * @author Nick Brown
 * @email  nicholas.brown@my.uwrf.edu
 * @author John Wagner 
 * @email  john.wagner@my.uwrf.edu
 * 
 * @date December 1st 2013
 *
 */
//parameterized test
@RunWith (Parameterized.class)
public class ShapeTests {
	//shape instance
	private tatrus.Shape shape;
	
	//Integer for parameters
	private Integer s;

	//constructor for ShapeTests
	public ShapeTests(Integer inS){
		this.s = inS;
	}

	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * Sets up a shape instance for testing
	 * purposes.
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
	shape = new tatrus.Shape(s);
	}

	/**
	 * Initial combinations for parametric tests that
	 * are related to Shape type numbers [0-6] or 7
	 * different combinations.
	 * @return List<Integer[]> 
	 */
	@Parameters
	public static List<Integer[]> values(){
		Integer[][] sList = new Integer[][] { {0},{1},{2},{3},{4},{5},{6} };
		return Arrays.asList(sList);
	}
	
	/**
	 * Tears down Shape instance after each test pass.
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		shape = null;
	}
	
	/**
	 * Test method for {@link tatrus.Shape#getColor()}.
	 * Tests method to directly check that each shape has
	 * corresponding color.
	 */
	@Test
	public final void testGetColor() {
		if(this.s == 0){
			assertEquals(Color.CYAN, shape.getColor());
		} else if (this.s == 1){
			assertEquals(Color.YELLOW, shape.getColor());
		} else if (this.s == 2){
			assertEquals(Color.MAGENTA, shape.getColor());
		} else if (this.s == 3){
			assertEquals(Color.GREEN, shape.getColor());
		} else if (this.s == 4){
			assertEquals(Color.RED, shape.getColor());
		} else if (this.s == 5){
			assertEquals(Color.BLUE, shape.getColor());
		} else if (this.s == 6){
			assertEquals(Color.ORANGE, shape.getColor());
		}
	}

	/**
	 * Test method for {@link tatrus.Shape#getColumns()}.
	 * Checks each shape for correct column allotment.
	 */
	@Test
	public final void testGetColumns() {
		if(this.s == 0){
			assertEquals(4, shape.getColumns());
		} else if (this.s == 1){
			assertEquals(2, shape.getColumns());
		} else {
			assertEquals(3, shape.getColumns());
		}
		
		}

	/**
	 * Test method for {@link tatrus.Shape#getRows()}.
	 * Checks each shape for correct row allotment.
	 */
	@Test
	public final void testGetRows() {
		if(this.s == 0){
			assertEquals(4, shape.getColumns());
		} else if (this.s == 1){
			assertEquals(2, shape.getColumns());
		} else {
			assertEquals(3, shape.getColumns());
		}	
		
	}

	/**
	 * Test method for {@link tatrus.Shape#getShapeGridSize()}.
	 * Checks each shape for for correct grid size.
	 */
	@Test
	public final void testGetShapeGridSize() {
		if(this.s == 0){
			assertEquals(4, shape.getShapeGridSize());
		} else if (this.s == 1){
			assertEquals(2, shape.getShapeGridSize());
		} else {
			assertEquals(3, shape.getShapeGridSize());
		}	
	}
	
	/**
	 * Test method for {@link tatrus.Shape#getType()}.
	 * Checks to make sure each shape is correctly matching
	 * our type numbers.
	 */
	@Test
	public final void testGetType() {
		assertEquals((int)this.s,shape.getType());
	}

	/**
	 * Test method for {@link tatrus.Shape#getColumnIndex()}.
	 * Checks to make sure each shape gets column index.
	 */
	@Test
	public final void testGetColumnIndex() {
		if(this.s == 0){
			assertEquals(3, shape.getColumnIndex());
		} else {
			assertEquals(4, shape.getColumnIndex());
		}
	}

	/**
	 * Test method for {@link tatrus.Shape#getLeftOffset(int)}.
	 * Tests left offset of applicable shapes.
	 */
	@Test
	public final void testGetLeftOffset() {
		if (this.s < 4)
		assertEquals(0, shape.getLeftOffset((int)this.s));
	}

	/**
	 * Test method for {@link tatrus.Shape#getRightOffset(int)}.
	 * Tests right offset of applicable shapes.
	 */
	@Test
	public final void testGetRightOffset() {
		if (this.s < 3)
		assertEquals(0, shape.getRightOffset((int)this.s));
		if (this.s == 3)
			assertEquals(1, shape.getRightOffset((int)this.s));
	}

	/**
	 * Test method for {@link tatrus.Shape#getUpperOffset(int)}.
	 * Tests upper offset of applicable shapes.
	 */
	@Test
	public final void testGetUpperOffset() {
		if(this.s == 0){
			assertEquals(2, shape.getUpperOffset((int)this.s));
		} else if (this.s == 1){
			assertEquals(0, shape.getUpperOffset((int)this.s));
		} else if (this.s == 2){
			assertEquals(1, shape.getUpperOffset((int)this.s));
		} else if (this.s == 3){
			assertEquals(0, shape.getUpperOffset((int)this.s));
		}
		
	}

	/**
	 * Test method for {@link tatrus.Shape#getLowerOffset(int)}.
	 * Tests lower offset of applicable shapes.
	 */
	@Test
	public final void testGetLowerOffset() {
		if(this.s == 0){
			assertEquals(1, shape.getLowerOffset((int)this.s));
		}else if (0< this.s && this.s < 4 ){
		assertEquals(0, shape.getLowerOffset((int)this.s));	
		} 
	}

}
